import Head from 'next/head';
import RootPropTable from '../../../components/prop-tables/RootPropTable';
import StateOptionsTable from '../../../components/prop-tables/StateOptionsTable';
import EnableOrderingExample from '../../../examples/enable-row-ordering';
import EnableDraggingExample from '../../../examples/enable-row-dragging';

<Head>
  <title>Row Ordering/DnD Feature Guide - Material React Table V1 Docs</title>
  <meta
    name="description"
    content="How to use and customize the row drag and drop and row ordering features of Material React Table"
  />
</Head>

## Row Ordering (DnD) Feature Guide

Material React Table has exposed all the APIs necessary to enable rich row drag-and-drop features that you can easily build to meet your needs. This includes the ability to reorder rows, drag rows to other tables, or drag rows to other UI in your application.

> This is not the [Sorting Guide](/docs/guides/sorting), which is a different feature.

### Relevant Props

<RootPropTable
  onlyProps={
    new Set([
      'enableRowOrdering',
      'muiTableBodyRowDragHandleProps',
      'onDraggingRowChange',
      'onHoveredRowChange',
    ])
  }
/>

### Relevant State

<StateOptionsTable onlyProps={new Set(['draggingRow', 'hoveredRow'])} />

### Enable Row Ordering

A common use for row drag and drop is to allow users to reorder rows in a table. This can be done by setting the `enableRowOrdering` prop to `true`, then setting up an `onDragEnd` event handler on the `muiTableBodyRowDragHandleProps` prop.

```jsx
<MaterialReactTable
  columns={columns}
  data={data}
  enableRowOrdering
  enableSorting={false} //usually you do not want to sort when re-ordering
  muiTableBodyRowDragHandleProps={{
    onDragEnd: (event, data) => {
      //data re-ordering logic here
    },
  }}
/>
```

<EnableOrderingExample />

### Drag and Drop Rows to Other UI or Tables

The drag-and-drop features are not limited to just internally within the same table. You can also use them to drag rows to other UI elements in your application or even to other tables. This can be done by setting the `enableRowDragging` prop to `true` and setting up an `onDragEnd` event handler on the `muiTableBodyRowDragHandleProps` prop to perform whatever logic you want to happen when a row is dropped.

<EnableDraggingExample />

View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-row-ordering-examples)**
